# -*- coding: utf-8 -*-
# -------------------------------------------------
# File Name： example_data_transfer
# Description :
# Author : 'li'
# date： 2022/5/23
# -------------------------------------------------
# Change Activity:
# 2022/5/23:
# -------------------------------------------------

from typing import Set, Union

import uvicorn
from fastapi import FastAPI
from pydantic import BaseModel
from starlette.staticfiles import StaticFiles

from ml.micro_service.misc import get_swagger_static_file_dir

app = FastAPI()


class Image(BaseModel):
    url: str
    name: str  # fsdfs


class Item(BaseModel):
    name: str  # dsad
    description: Union[str, None] = None  # sdfad
    price: float
    tax: Union[float, None] = None
    tags: Set[str] = set()
    image: Union[Image, None] = None


@app.post("/items/{item_id}")
async def update_item(item_id: int, item: Item):
    """

    Args:
        item_id:
        item:

    Returns:

    """
    results = {"item_id": item_id, "item": item}
    return results


def _main():
    swagger_dir = get_swagger_static_file_dir()
    app.mount('/static', StaticFiles(directory=swagger_dir), name='static')
    uvicorn.run(app, host="0.0.0.0", port=8000)


if __name__ == '__main__':
    _main()
